var dataJs = require("data.js");
Page({
    data: {
        // 
        firstHidden: false,
        chooseHidden: true,
        adHidden: true,
        resultHidden: true,
        girl: '选择女生星座',
        boy: '选择男生星座',
        // 点击的时候 firl为true，boy为false
        currentClick: null,
        resultData: dataJs.xingZuoData,
        aiqing: null,
        youqing: null,
        qinqing: null,
        jianyi: null,
        xingzuo: [
          {name: '白羊座', time:'3.21-4.19', img: '../../images/xingzuo/muyangzuo.png'},
          {name: '金牛座', time:'4-20-5-20', img: '../../images/xingzuo/jinniuzuo.png'},
          {name: '双子座', time:'5.21-6.21', img: '../../images/xingzuo/shuangzizuo.png'},
          {name: '巨蟹座', time:'6.22-7.22', img: '../../images/xingzuo/juxiezuo.png'},
          {name: '狮子座', time:'7.23-8.22', img: '../../images/xingzuo/shizizuo.png'},
          {name: '处女座', time:'8.23-9.22', img: '../../images/xingzuo/chunvzuo.png'},
          {name: '天秤座', time:'9.23-10.23', img: '../../images/xingzuo/tianchengzuo.png'},
          {name: '天蝎座', time:'10.24-11.22', img: '../../images/xingzuo/tianhezuo.png'},
          {name: '射手座', time:'11.22-12.21', img: '../../images/xingzuo/sheshouzuo.png'},
          {name: '摩羯座', time:'12.22-1.19', img: '../../images/xingzuo/mojiezuo.png'},
          {name: '水瓶座', time:'1.20-2.18', img: '../../images/xingzuo/shuipingzuo.png'},
          {name: '双鱼座', time:'2.19-3.20', img: '../../images/xingzuo/shuangyuzuo.png'},
        ]
    },
    choose: function(event) {
        let isGirl = event.currentTarget.id == 'boy' ? false : true;
        this.setData({
            firstHidden: false,
            chooseHidden: false,
            currentClick: event.currentTarget.id
        });
    },
    chooseXing: function(event) {
      console.log(event.currentTarget.dataset.index);
      let xingzuo = this.data.xingzuo[event.currentTarget.dataset.index];
      if (this.data.currentClick == 'boy'){
        this.setData({boy: xingzuo.name});
      } else{
        this.setData({girl: xingzuo.name});
      }
      this.setData({chooseHidden: true});
    },
    getResult: function() {
      let key = this.data.boy+this.data.girl+"配对";
      let result = this.getResultJson(key);

      this.setData({
        resultHidden: false,
        firstHidden: true,
        aiqing: this.getJson("爱情配对", result),
        qinqing: this.getJson("亲情配对", result),
        youqing: this.getJson("友情配对", result),
        jianyi: this.getJson("配对建议和注意事项", result)
      });

    },
    getJson: function(key, jsonObj) {
      for(var item in jsonObj){ 
        if(item == key){ //item 表示Json串中的属性，如'name' 
            var jValue=jsonObj[item];//key所对应的value 
            return jValue;
        }
      }
    },
    getResultJson: function(key) {
      let jsonObj = this.data.resultData;
      for(var item in jsonObj){ 
        if(item == key){ //item 表示Json串中的属性，如'name' 
            var jValue=jsonObj[item];//key所对应的value 
            return jValue;
        }
      }
    },
    onLoad : function(options) {

    }
})